import { _decorator, Button, Component, Node } from 'cc';
import { UIPanel } from '../../UI/Panel/UIPanel';
import { UILayer } from '../../UI/Panel/UILayer';
import { UIManager } from '../../UI/UIManager';
import { ChannelManager } from '../../Channel/ChannelManager';
const { ccclass, property } = _decorator;

@ccclass('TestPanel')
export class TestPanel extends UIPanel {
    @property({ type: Node, displayName: "关闭界面" })
    private btnClose: Node = null;
    @property({ type: Node, displayName: "销毁界面" })
    private btnDestory: Node = null;

    protected _layer: UILayer = UILayer.BOTTOM;

    public OnInit(data?: any): void {
        this.btnClose.on(Button.EventType.CLICK, () => { this.Hide(); });
        this.btnDestory.on(Button.EventType.CLICK, () => { this.Destroy(); });

        let Layout = this.node.getChildByName('Layout');

        let btn_toast = Layout.getChildByName('Btn_Toast');
        let btn_notice = Layout.getChildByName('Btn_Notice');
        let btn_dialog1 = Layout.getChildByName('Btn_Dialog1');
        let btn_dialog2 = Layout.getChildByName('Btn_Dialog2');
        let btn_dialog3 = Layout.getChildByName('Btn_Dialog3');
        let btn_loading = Layout.getChildByName('Btn_Loading');
        btn_toast.on(Button.EventType.CLICK, this.OnToast, this);
        btn_notice.on(Button.EventType.CLICK, this.OnNotice, this);
        btn_dialog1.on(Button.EventType.CLICK, this.OnDialog1, this);
        btn_dialog2.on(Button.EventType.CLICK, this.OnDialog2, this);
        btn_dialog3.on(Button.EventType.CLICK, this.OnDialog3, this);
        btn_loading.on(Button.EventType.CLICK, this.ShowLoading, this);
    }

    public OnShow(data?: any): void {
        console.log(this.constructor.name + '.OnShow', data);
    }

    public OnHide(): void {
        console.log(this.constructor.name + '.OnHide');
    }

    public OnDestroy(): void {
        console.log(this.constructor.name + '.OnDestroy');
    }

    /**
    * Toast提示
    */
    private OnToast() {
        ChannelManager.GetInstance().ShowToast("toast提示测试");
    }
    /**
     * 通知
     */
    private OnNotice() {
        ChannelManager.GetInstance().ShowNotice("通知测试");
    }

    /**
     * 显示提示框
     */
    private OnDialog1() {
        console.log('On Dialog 1')
        ChannelManager.GetInstance().ShowDialog({
            title: "提 示",
            content: "Dialog测试1，常规提示框",
            sure: function () {
                console.log("Dialog测试1", ">>>>>sure");
            },
            cancel: function () {
                console.log("Dialog测试1", ">>>>>cancel");
            }
        });
    }

    /**
     * 显示提示框，仅显示关闭按键
     */
    private OnDialog2() {
        ChannelManager.GetInstance().ShowDialog({
            title: "提 示",
            content: "Dialog测试2，显示提示框，仅显示关闭按键",
            sure_label: "关 闭"
        });
    }

    /**
     * 显示提示框，显示广告icon
     */
    private OnDialog3() {
        ChannelManager.GetInstance().ShowDialog({
            title: "提 示",
            content: "Dialog测试3，显示提示框，显示广告icon",
            sure: function () {
                console.log("Dialog测试3", ">>>>>sure");
            },
            cancel: function () {
                console.log("Dialog测试3", ">>>>>cancel");
            },
            ad_icon: true
        });
    }

    /**显示加载 */
    private ShowLoading() {
        ChannelManager.GetInstance().ShowLoading();
        this.scheduleOnce(() => {
            ChannelManager.GetInstance().HideLoading();
        }, 2);
    }
}


